<template>
  <el-dialog
    :title="title"
    :visible.sync="open"
    append-to-body
    :modal="false"
    top="74px"
    class="container-dailog transition-box"
    :class="$store.state.app.sidebar.opened ? 'openSidebar' : 'hideSidebar'"
    @close="close"
  >
    <div>
      <el-row :gutter="20" class="margin-bottom-20">
        <el-col :span="1.5" class="flex align-center">
          <span class="margin-right-20 text-cut">模板名称</span>
          <el-input disabled v-model="form.templatesName"></el-input>
        </el-col>
        <el-col :span="1.5" class="flex align-center">
          <span class="margin-right-20">所属组织</span>
          <treeselect
            disabled
            v-model="form.deptId"
            :options="deptOptions"
            :show-count="true"
            placeholder="请选择组织"
          />
        </el-col>
        <!-- <el-col :span="1.5" class="flex align-center" style="height: 36px;">
          <span class="margin-right-20">下级组织分享</span>
          <el-switch />
        </el-col> -->
        <el-col :span="1.5" class="flex align-center" style="height: 36px;">
          <span>采集方式：</span>
          <dict-tag
            :options="dict.type.acquisition_method"
            :value="form.acquisitionMethodValue"
          />
        </el-col>
        <el-col :span="1.5" class="flex align-center" style="height: 36px;">
          <span>状态判断方式：</span>
          <dict-tag
            :options="dict.type.status_config"
            :value="form.statusConfig"
          />
        </el-col>
      </el-row>
      <div>
        <div class="border padding-tb-10 padding-lr-20 bg-gray">
          <div class="margin-bottom-10">
            <label class="font-16">变量列表</label>
          </div>
          <div>
            <div class="flex justify-between margin-bottom-10">
              <!-- <el-row :gutter="10">
                <el-col :span="1.5">
                  <span class="margin-right-20">协议和产品</span>
                  <el-select placeholder="请选择协议和产品">
                    <el-option />
                  </el-select>
                </el-col>
              </el-row> -->
              <el-row :gutter="10">
                <el-col :span="1.5">
                  <el-select v-model="varListQueryParams.variableTypeId" placeholder="请选择变量类型">
                    <el-option
                      v-for="dict in [...[{label: '全部变量', value: ''}], ...dict.type.variable_type]"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </el-col>
                <el-col :span="1.5">
                    <el-input
                      placeholder="请输入变量名称"
                      clearable
                      v-model="varListQueryParams.variableName"
                    />
                </el-col>
                <el-col :span="1.5">
                  <el-button type="primary" @click="varListQueryHandle" size="small">查询</el-button>
                </el-col>
              </el-row>
            </div>
            <el-table height="300px"  :data="valList">
              <el-table-column label="序号" type="index" />
              <el-table-column label="变量名称" prop="variableName" align="center" />
              <el-table-column label="变量类型" prop="variableTypeName" align="center" />
              <el-table-column label="寄存器"  align="center" >
                <template slot-scope="scope">
                {{ scope.row.storageValue+''+scope.row.serialNum }}
              </template>
              </el-table-column>
              <el-table-column label="读写" prop="readWriteWayName" align="center" />
              <el-table-column label="存储方式" prop="storageMethodName" align="center" />
            </el-table>
          </div>
        </div>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { listDeviceVariable,listTempVariable } from "@/api/iot/device";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  dicts: ["variable_type", "acquisition_method", "status_config"],
  components: { Treeselect },
  props: {
    supThis: {
      type: Object,
      default: null,
    },
    deptOptions: {
      type: Array,
      default: () => [],
    }
  },
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      tabActiveName: "detail",
      // 表单参数
      form: {},
      varListQueryParams: {
        variableName: '',
        variableTypeId: ''
      },
      valList: []
    };
  },
  methods: {
    // 表单重置
    reset() {
      this.form = {
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        id: null,
        templatesName: null,
        deptId: null,
        acquisitionMethod: null,
        protocol: null,
        statusConfig: null,
        deptName: null,
        variableCount: null,
        deviceCount: null,
      };
    },
    varListQueryHandle() {
      listTempVariable({
        deviceTemplateId: this.form.id,
        variableName: this.varListQueryParams.variableName,
        variableType: this.varListQueryParams.variableTypeId
      }).then((response) => {
        this.valList = response.rows
      });
    },
    close() {
      this.valList = []
      this.varListQueryParams.variableName = ''
      this.varListQueryParams.variableTypeId = ''
    }
  },
};
</script>

<style lang="scss" scoped>
.newdevInfoBoxLeftPic {
  width: 100px;
  height: 100px;
  .deviceImg {
    width: auto;
    height: auto;
    max-width: 100px;
    max-height: 100px;
    margin: auto;
  }
  .text {
    color: #fff;
    letter-spacing: 0;
    font-weight: 400;
    line-height: 26px;
    top: -2px;
  }
}
.parameter-content {
  padding: 20px 0 20px 200px;
  label {
    height: auto;
    width: 190px;
  }
  p {
    width: auto;
    max-width: 300px;
    display: block;
    word-break: break-all;
  }
}
.map-container {
  width: 100%;
  height: 100%;
}
</style>
